package com.example.stomp.websocket.service.controller;

import com.example.stomp.websocket.service.bean.Greeting;
import com.example.stomp.websocket.service.bean.HelloMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.util.HtmlUtils;

/**
 * @author ZhenWuWang
 */
@Controller
public class GreetingController
{

    SimpleBrokerMessageHandler simpleBrokerMessageHandler;
    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage helloMessage) throws Exception
    {
        Thread.sleep(3000);
        System.out.println("=======" + helloMessage.toString());
        return new Greeting("hello,"+ HtmlUtils.htmlEscape(helloMessage.getName()) + "!");
    }
}
